<?php
class sql_database_queries extends db_driver_mysql
{

     var $db  = "";
     var $tbl = "";
     
    function sql_database_queries( $obj )
    {
    	$this->db = &$obj;
    	
    	if ( ! $this->db->obj['sql_tbl_prefix'] )
    	{
    		$this->db->obj['sql_tbl_prefix'] = 'ibf_';
    	}
    	
    	$this->tbl = $this->db->obj['sql_tbl_prefix'];
    }
	
    function table_market_versions()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_versions (
		    	 upgrade_id int(10) NOT NULL auto_increment,
				 version_id int(10) NOT NULL,
				 version_name varchar(255) NOT NULL,
				 up_time int(10) NOT NULL,
				PRIMARY KEY (upgrade_id) 
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_categories()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_categories (
				 cat_id int(10) NOT NULL auto_increment,
				 cat_parent_id int(10) NOT NULL default '-1',
				 cat_icon varchar(255) NOT NULL default '',
				 cat_name varchar(255) NOT NULL default '',
				 cat_description text NOT NULL,
				 price_multiplier float(15,10) NOT NULL default '1.0000000000',
				 cat_tax float(15,10) NOT NULL default '0.0000000000',
				 cat_order smallint(5) NOT NULL default '0',
				 PRIMARY KEY  (cat_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_items()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_items (
				 item_id int(10) NOT NULL auto_increment,
				 filename varchar(255) NOT NULL default '',
				 item_name varchar(255) NOT NULL default '',
				 item_description text NOT NULL,
				 category int(10) NOT NULL default '0',
				 icon varchar(255) NOT NULL default '',
				 hide_item tinyint(1) NOT NULL default '0',
				 base_price bigint(19) NOT NULL default '0',
				 base_resell bigint(19) NOT NULL default '0',
				 tax float(15,10) NOT NULL default '0.0000000000',
				 stock int(10) NOT NULL default '0',
				 allow_resell tinyint(1) NOT NULL default '0',
				 resell_putback tinyint(1) NOT NULL default '0',
				 restock tinyint(1) NOT NULL default '0',
				 restock_when int(10) NOT NULL default '-1',
				 restock_minute smallint(2) NOT NULL default '0',
				 restock_hour smallint(2) NOT NULL default '0',
				 restock_day mediumint(3) NOT NULL default '0',
				 restock_howmuch int(10) NOT NULL default '0',
				 restock_time int(10) NOT NULL default '0',
				 inventory_limit int(10) NOT NULL default '0',
				 item_config text NOT NULL,
				 settings text NOT NULL,
				 limit_buy text NOT NULL,
				 limit_use text NOT NULL,
				 expire_time int(10) NOT NULL default '0',
				 expire_unit int(10) NOT NULL default '0',
				 PRIMARY KEY  (item_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_inventory()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_inventory (
				 i_id int(10) NOT NULL auto_increment,
				 member_id mediumint(8) NOT NULL default '0',
				 item int(10) NOT NULL default '0',
				 price_bought bigint(19) NOT NULL default '0',
				 resell_price bigint(19) NOT NULL default '0',
				 time_bought int(10) NOT NULL default '0',
				 settings TEXT NOT NULL,
				 expired int(10) NOT NULL default '0',
				 PRIMARY KEY  (i_id),
				 KEY member_id (member_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_buy_logs()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_buy_logs (
				 log_id int(10) NOT NULL auto_increment,
				 method enum('buy','resell') NOT NULL default 'buy',
				 member_id mediumint(8) NOT NULL default '0',
				 item_id int(10) NOT NULL default '0',
				 ip_address varchar(15) NOT NULL default '',
				 time_bought int(10) NOT NULL default '0',
				 quanity bigint(19) NOT NULL default '0',
				 price_bought bigint(19) NOT NULL default '0',
				 resell_price bigint(19) NOT NULL default '0',
				 tax_total bigint(19) NOT NULL default '0',
				 category int(10) NOT NULL default '0',
				 item_name varchar(255) NOT NULL default '',
				 item_description text NOT NULL,
				 icon varchar(255) NOT NULL default '',
				 category_name varchar(255) NOT NULL default '',
				 PRIMARY KEY  (log_id),
				 KEY member_id (member_id),
				 KEY receipt_id (method,member_id,time_bought)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_item_logs()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_item_logs (
				 l_id int(10) NOT NULL auto_increment,
				 member_id mediumint(8) NOT NULL default '0',
				 item_id int(10) NOT NULL default '0',
				 inv_id int(10) NOT NULL default '0',
				 ip_address varchar(15) NOT NULL default '',
				 l_time int(10) NOT NULL default '0',
				 log_message text NOT NULL,
				 PRIMARY KEY  (l_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_plugins()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_plugins (
				 link varchar(255) NOT NULL default '',
				 name varchar(255) NOT NULL default '',
				 filename varchar(255) NOT NULL default '',
				 position mediumint(8) NOT NULL default '0',
				 plugin_config text NOT NULL,
				 view_permission mediumtext NOT NULL,
				 use_permission mediumtext NOT NULL,
				 PRIMARY KEY  (link)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_fee_logs()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_fee_logs (
				 l_id int(10) NOT NULL auto_increment,
				 member_id mediumint(8) NOT NULL default '0',
				 l_time int(10) NOT NULL default '0',
				 location varchar(255) NOT NULL default '',
				 l_amount int(10) NOT NULL default '0',
				 PRIMARY KEY  (l_id),
				 KEY member_id (member_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_reward_logs()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_reward_logs (
				 l_id int(10) NOT NULL auto_increment,
				 member_id mediumint(8) NOT NULL default '0',
				 l_time int(10) NOT NULL default '0',
				 location varchar(255) NOT NULL default '',
				 l_amount int(10) NOT NULL default '0',
				 PRIMARY KEY  (l_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_wages()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_wages (
				 w_id mediumint(8) NOT NULL auto_increment,
				 to_who enum('m','g') NOT NULL default 'm',
				 id_who mediumint(8) NOT NULL default '0',
				 how_much bigint(19) NOT NULL default '0',
				 next_payment int(10) NOT NULL default '0',
				 w_how tinyint(1) NOT NULL default '0',
				 w_when int(10) NOT NULL default '0',
				 w_day mediumint(3) NOT NULL default '0',
				 w_hour smallint(2) NOT NULL default '0',
				 w_minute smallint(2) NOT NULL default '0',
				 PRIMARY KEY  (w_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_wages_collected()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_wages_collected (
				 c_id int(10) NOT NULL auto_increment,
				 time_collected int(10) NOT NULL default '0',
				 to_who enum('m','g') NOT NULL default 'm',
				 id_who mediumint(8) NOT NULL default '0',
				 how_much bigint(19) NOT NULL default '0',
				 PRIMARY KEY  (c_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_temp_convert()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_temp_convert (
				 c_type varchar(255) NOT NULL default '0',
				 the_data TEXT NOT NULL
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_taxes()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_taxes (
				 t_id int(11) NOT NULL auto_increment,
				 applying enum('post','hand') NOT NULL default 'post',
				 t_week tinyint(4) NOT NULL default '0',
				 t_day tinyint(4) NOT NULL default '0',
				 t_hour tinyint(4) NOT NULL default '0',
				 t_minute tinyint(4) NOT NULL default '0',
				 tax_fix bigint(20) NOT NULL default '0',
				 tax_percent float(15,10) NOT NULL default '0.0000000000',
				 tax_pmin bigint(20) NOT NULL default '0',
				 tax_psub bigint(20) NOT NULL default '0',
				 range_min bigint(20) NOT NULL default '0',
				 range_max bigint(20) NOT NULL default '0',
				 PRIMARY KEY  (t_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function table_market_tax_log()
    {
    	return "CREATE TABLE ".SQL_PREFIX."market_tax_logs (
				 l_id int(11) NOT NULL auto_increment,
				 member_id mediumint(9) NOT NULL default '0',
				 tax_id int(11) NOT NULL default '0',
				 amount bigint(20) NOT NULL default '0',
				 l_time int(11) NOT NULL default '0',
				 PRIMARY KEY  (l_id)
				) TYPE=".$this->db->connect_vars['mysql_tbl_type'];
    }
    
    function add_text_field( $a )
    {
    	return "ALTER TABLE ".SQL_PREFIX.$a['table']." ADD ".$a['field']." text NOT NULL";
    }
    
} // end class


?>